/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Action;

import Entity.Tickets;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Cyrax
 */
@Stateless
public class TicketsSessionBean implements TicketsSessionBeanLocal {

    @PersistenceContext(unitName = "EasyTickets-ejbPU")
    private EntityManager em;

    public void persist(Object object) {
        em.persist(object);
    }

    @Override
    public List<Tickets> listAllTickets() {


        List<Tickets> tk;
        tk = em.createNamedQuery("Tickets.findAll").getResultList();
        return tk;


    }

//    @Override
//    public List<Tickets> searchTickets(String email) {
//        List<Tickets> tk = null;
//
//        tk = em.createQuery("SELECT t FROM Tickets t WHERE t.email like :email").setParameter("email", "%" + email + "%").getResultList();
//        System.out.println("userName : " + email);
//
//
//        return tk;
//    }

    @Override
    public void updateTickets(int tkId, boolean status) {
        Tickets ts = em.find(Tickets.class, tkId);
        if (ts != null) {

            ts.setStatus(status);

            em.persist(ts);
        } else {
            System.out.println("Not found tcId  to Update");
        }
    }
      @Override
    public void DeleteTickets(Tickets tk) {

        if (tk != null) {
            em.remove(em.merge(tk));
        } else {
            System.out.println("Not found Tk to delete");
        }
    }
}
